﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SearchCompare
{
    class Program
    {
        static unsafe void Main(string[] args)
        {

            #region tree testing
            #region dynamic tree
            Node* root = null;
            int added = 0;
            int dups = 0;
            //generate 100k ushorts
            
            Random rng = new Random();
            for (int i = 0; i < 100000; i++)
            {
                Node* n = (Node*)System.Runtime.InteropServices.Marshal.AllocHGlobal(sizeof(Node));
                n->_value = (ushort)rng.Next(65535);
                n->_left = null;
                n->_right = null;
                n->_height = 1;

                //fill the tree - no duplicate values

                if (TreeUtil.AVLAdd(n, ref root))
                {
                    added++;
                    //Console.WriteLine("Added {0}", n->_value);
                }
                else
                {
                    dups++;
                    //Console.WriteLine("Duplicate: {0}", n->_value);
                }

            }
            #endregion dynamic tree
            #region static tree
            /*
            Node*[] nodes = new Node*[7];
            ushort[] values = {1,0,5,3,2,4,6};
            int[] heights = {4,1,3,2,1,1,1};

            for (int i = 0; i < 7; i++)
            {
                nodes[i] = (Node*)System.Runtime.InteropServices.Marshal.AllocHGlobal(sizeof(Node));
                nodes[i]->_value = values[i];
                nodes[i]->_height = heights[i];
                nodes[i]->_left = null;
                nodes[i]->_right = null;

                TreeUtil.Add(nodes[i], ref root);
            }
            */
            #endregion static tree
            //might as well print the tree I guess
            //should be printed in sorted order
            Console.WriteLine("Height: {0}", root->_height);
            Console.WriteLine("Elements Added: {0}. Duplicates: {1}.", added, dups);
            Console.WriteLine("Count: {0}", TreeUtil.Count(root));
            
            #endregion tree testing

            #region forest testing
            /*
            int added = 0, dup = 0;
            ushort addedValue = 0;
            Random rng = new Random();
            BinarySearchForest forest = new BinarySearchForest();

            for (int i = 0; i < 100000; i++)
            {
                Node* n = (Node*)System.Runtime.InteropServices.Marshal.AllocHGlobal(sizeof(Node));
                n->_value = (ushort)rng.Next(65536);
                addedValue = n->_value;
                n->_left = null;
                n->_right = null;

                //fill the forest - no duplicate values
                if (forest.AVLAdd(n))
                    added++;
                else
                    dup++;
            }

            //count the forest!
            forest.PrintHeights();
            
            Console.WriteLine("Added: {0}\nDuplicates: {1}", added, dup);
            Console.WriteLine("Comparisons: {0}", forest.MeasureComparisons(addedValue));
            */
            #endregion
            Console.Read();

        }
    }
}
